﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompositePattern.GeneralDemo
{
    /// <summary>
    /// 樹枝構件
    /// </summary>
    public class Composite : Component
    {
        /// <summary>
        /// 構件容器
        /// </summary>
        private List<Component> componentList = new List<Component>();

        /// <summary>
        /// 增加一個葉子構件或樹枝構件
        /// </summary>
        /// <param name="component"></param>
        public void add(Component component) {
            this.componentList.Add(component);
        }

        /// <summary>
        /// 刪除一個葉子構件或樹枝構件
        /// </summary>
        /// <param name="component"></param>
        public void remove(Component component)
        {
            this.componentList.Remove(component);
        }

        /// <summary>
        /// 獲得分支下的所有葉子構件和樹枝構件
        /// </summary>
        /// <param name="component"></param>
        public List<Component> getChildren( )
        {
            return this.componentList;
        }
    }
}
